<template>
	<view class="my-layout">
		<!-- 已认证 -->
		<view class="my-top-box" :class="[channelStore.myBigBgClassName]" :style="{paddingTop:safeTop + 'px'}" v-if="userStore.user.authStatus == '00' ">
			<!-- 导航 -->
			<view class="my-nav-box">
				<image class="nav-msg-icon" src="/static/my/nav_msg_icon.png" mode="aspectFit" @tap="showMessage"></image>
			</view>
			<!-- 用户信息 -->
			<view class="user-box" @tap="showUserInfo">
				<image class="user-photo" src="/static/operate/agent_photo.png" mode="aspectFit"></image>
				<view class="user-info">
					<text class="user-info-name">{{userStore.user.agentName}}</text>
					<text class="user-info-space">{{userStore.user.agentId}}</text>
					<text class="user-info-space">{{userStore.user.tel}}</text>
				</view>
				<xh-icon :style="{marginLeft:'auto'}" icon="icon_jiantou" color="#ffffff" size="36rpx"></xh-icon>
			</view>
		</view>
		<!-- 未认证 -->
		<view class="my-top-no-auth" :style="{paddingTop:safeTop + 20 + 'px'}" v-else>
			<image class="my-top-no-auth-icon" src="/static/my/my_top_icon.png" mode="aspectFit"></image>
			<text class="my-top-no-auth-text">POS服务商展业支付平台</text>
			<view class="my-top-no-auth-btn" :class="[userStore.user.authStatus == '02' ? 'my-top-no-auth-btn-waitting' : '']" @tap="showAuth">{{authBtnText}}</view>
		</view>
		<uv-gap height="20rpx" bgColor="#F7F7F7"></uv-gap>
		<!-- 菜单 -->
		<view class="my-menu-box" :class="[userStore.user.authStatus == '00' ? 'my-menu-box-auth' : '']">
			<view class="my-menu-item" v-for="item in channelStore.myMenuList" :key="item.type" @tap="didSelectItem(item)">
				<image class="my-menu-item-icon" :src="item.icon" mode="aspectFit"></image>
				<text class="my-menu-item-title">{{item.title}}</text>
				<view class="my-menu-right">
					<view v-if="item.type == 3 && userStore.user.authStatus == '00'">
						<text class="my-menu-right-text">{{userStore.user.qrCode}}</text>
						<text class="my-menu-right-copy" @tap="copyAction">复制</text>
					</view>
					<xh-icon icon="icon_jiantou" v-if="userStore.user.authStatus != '00'"></xh-icon>
				</view>	
			</view>
		</view>
		<xh-contact-pop ref="contactRef"></xh-contact-pop>
		<xh-auth-pop ref="authRef"></xh-auth-pop>
	</view>
</template>

<script setup>
	import { onLoad,onShow } from '@dcloudio/uni-app'
	import { ref,computed,nextTick } from 'vue'
	import { useChannelStore,useUserStore } from '@/common/stores'
	const safeTop = ref(0)
	const channelStore = useChannelStore()
	const userStore = useUserStore()
	const contactRef = ref(null)
	const authRef = ref(null)
	// 复制
	const copyAction = ()=>{
		uni.$utils.copy(userStore.user.qrCode)
	}
	// 认证按钮文字
	const authBtnText = computed(()=>{
		if(userStore.user.authStatus == '02') {
			return '审核中'
		}
		else if(userStore.user.authStatus == '03') {
			return '重新认证'
		}
		return '马上认证'
	})
	//去认证
	const showAuth = ()=>{
		if(userStore.user.authStatus == '02'){
			return
		}
		uni.navigateTo({
			url:'/pages/my/auth/auth'
		})
	}
	// 消息
	const showMessage = ()=>{
		uni.navigateTo({
			url:'/pages/my/message/message'
		})
	}
	// 用户信息
	const showUserInfo = ()=>{
		uni.navigateTo({
			url:'/pages/my/userinfo/userinfo'
		})
	}
	
	// 选择菜单项
	const didSelectItem = (item)=>{
		if(item.type <= 3 && userStore.user.authStatus != '00') {
			authRef.value.open()
			return
		}
		if(item.type == 1) {
			uni.navigateTo({
				url:'/pages/my/invoice/invoice'
			})
		}
		else if(item.type == 2) {
			uni.navigateTo({
				url:'/pages/my/my-policy/my-policy'
			})
		}
	    else if(item.type == 4) {
			contactRef.value.open()
		}
		else if(item.type == 5){
			uni.navigateTo({
				url:'/pages/my/about/about'
			})
		}
		else if(item.type == 6){
			uni.navigateTo({
				url:'/pages/my/setting/setting'
			})
		}
	}
	onShow(()=>{
		userStore.updateUserInfo()
	})
	onLoad( () => {
		safeTop.value = uni.getSystemInfoSync().safeAreaInsets.top
		nextTick(()=>{
			if(userStore.user.authStatus != '00') {
				authRef.value.open()
			}
		})
	})
</script>

<style lang="scss" scoped>
	.my-layout {
		background-color: white;
		min-height: 100vh;
		.my-top-bg-KDB {
			background-image: url('/static/home/home_top_bg_KDB@2x.png');
		}

		.my-top-bg-QB {
			background-image: url('/static/home/home_top_bg_QB@2x.png');
		}

		.my-top-bg-HHB {
			background-image: url('/static/my/my_top_bg_HHB@2x.png');
		}

		.my-top-box {
			background-repeat: no-repeat;
			background-size: 100% 100%;
			.my-nav-box {
				display: flex;
				align-items: center;
				justify-content: flex-end;
				padding: 0 30rpx;
				height: 44px;
				.nav-msg-icon {
					width: 52rpx;
					height: 52rpx;
				}
			}
			.user-box{
				display: flex;
				align-items: center;
				padding: 80rpx 30rpx;
				.user-photo{
					width: 144rpx;
					height: 144rpx;
				}
				.user-info{
					display: flex;
					flex-direction: column;
					color: #ffffff;
					font-size: 26rpx;
					margin-left: 20rpx;
					.user-info-name{
						font-size: 32rpx;
					}
					.user-info-space{
						margin-top: 10rpx;
					}
				}
			}
		}
		.my-top-no-auth{
			background-color: #ffffff;
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: center;
			padding: 50rpx;
			.my-top-no-auth-icon{
				width: 212rpx;
				height: 138rpx;
			}
			.my-top-no-auth-text{
				color: #3F4C5D;
				font-size: 28rpx;
				margin: 30rpx 0;
			}
			.my-top-no-auth-btn{
				color: #ffffff;
				font-size: 28rpx;
				background-color: $xh-red-color;
				height: 60rpx;
				line-height: 60rpx;
				padding: 0 50rpx;
				border-radius: 30rpx;
			}
			.my-top-no-auth-btn-waitting{
				background-color: #11AC28;
			}
		}
		.my-menu-box-auth{
			border-top-left-radius: 20rpx;
			border-top-right-radius: 20rpx;
			margin-top: -30rpx;
			padding: 30rpx 54rpx;
		}
		.my-menu-box{
			background-color: #ffffff;
			padding:20rpx 54rpx;
			.my-menu-item{
				display: flex;
				align-items: center;
				padding: 30rpx 0;
				.my-menu-item-icon{
					width: 48rpx;
					height: 48rpx;
				}
				.my-menu-item-title{
					margin-left: 20rpx;
				}
				.my-menu-right{
					margin-left: auto;
					.my-menu-right-copy{
						color: $xh-theme-color;
						margin-left: 10rpx;
					}
					.my-menu-right-text{
						color: $xh-orange-color;
					}
				}
			}
		}
	}
</style>